#include <iostream>
#include <vector>
using namespace std;

int find(vector<int>& father, int p)
{
    int i = p;
    int size = 0;
    vector<int> st;
    while (i != father[i])
    {
        st.push_back(i);
        i = father[i];
    }
    while (!st.empty())
    {
        father[st.back()] = i;
        st.pop_back();
    }
    return i;
}

bool isSameSet(vector<int>& father, int x, int y)
{
    return find(father, x) == find(father, y);
}

void Union(vector<int>& father, int x, int y)
{
    int fx = find(father, x);
    int fy = find(father, y);
    if (fx != fy)
        father[fx] = fy;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> father(n + 10);
    for (int i = 1; i <= n; i++)
        father[i] = i;
    while (m--)
    {
        int opt, x, y;
        scanf("%d%d%d", &opt, &x, &y);
        if (opt == 1)
        {
            if (isSameSet(father, x, y))
                printf("Yes\n");
            else
                printf("No\n");
        }
        if (opt == 2)
            Union(father, x, y);
    }
    return 0;
}